class Solution {
public:
    int majorityElement(vector<int>& nums) {
        unordered_map<int, int> ump;
        int ans, cnt = 0;
        for (auto x : nums) {
            ump[x]++;
            if (ump[x] > cnt) {
                ans = x;
                cnt = ump[x];
            }
        }
        return ans;
    }
};
